cd "/Users/flheeb/Dropbox (CSP)/Scope Insensitivity/04 Analysis/1_Replication_Code/2_Private_Investors_Joint_Evaluation"

capture log close
log using "log.log", replace
clear
set more off

*** Install Packages ***

*ssc install logout
*ssc install tabout


*** Load dataset ***

use "Pseudo_Dataset_JE.dat", clear


*** Clean Dataset ***

* Drop investors who do not think climate change is a problem

drop if ClimateProblem < 0 // !!!!

* Drop participant who do not agree with the elicited WTP and are not willing to repeat elicitation

drop if control_failed_1 == 1 & elicitation_repeated_1 == 0
drop if control_failed_2 == 1 & elicitation_repeated_2 == 0


*** Winsorize WTP for Fund B (WTP_B) and Fund C (WTP_C) at 5% & 95% level ***

winsor2 WTP_B, replace cuts(5 95)
winsor2 WTP_C, replace cuts(5 95)

save "Dataset_JE_clean.dat", replace


*** Descriptives (Section 3.2) ***

sort treatment
by treatment: summarize WTP_B WTP_C


*** Non-parametric test (Section 3.2) ***

* Testing for differences between the WTP for Fund B and Fund C for each treatment (within subject)

drop if treatment != "Low Impact Range"
logout, save(signrank_LowImpactRange_WTP_BvsC) replace: signrank WTP_B = WTP_C
use "Dataset_JE_clean.dat", clear

drop if treatment != "High Impact Range"
logout, save(signrank_HighImpactRange_WTP_BvsC) replace: signrank WTP_B = WTP_C
use "Dataset_JE_clean.dat", clear

* Testing for differences between the WTP for Fund B between treatments

logout, save(ranksum_WTP_B_HighvsLow) replace: ranksum WTP_B, by(treatment)

* Testing for differences between the WTP for Fund C between treatments

logout, save(ranksum_WTP_C_HighvsLow) replace: ranksum WTP_C, by(treatment)


*** Investor level impact-sensitivity analysis (Section 3.2) ***

gen rWTP = (WTP_C / WTP_B)
gen insensitive = (rWTP == 1)
gen Sensitivity = "1 Inverse Sensitivity (x < 1)" if rWTP < 1
replace Sensitivity = "2 Insensitive" if rWTP == 1
replace Sensitivity = "3 Low Sensitivity" if rWTP > 1 & rWTP <= 1.7384615
replace Sensitivity = "4 High Sensitivity" if rWTP >=1.7384615
tabout Sensitivity using Sensitivity.xls, replace sum cells(mean WTP_B mean WTP_C N WTP_B mean rWTP)

gen HighSensitivity = (Sensitivity == "4 High Sensitivity")
gen LowSensitivity = (Sensitivity == "3 Low Sensitivity")
gen WTP_AVG = (WTP_B + WTP_C) / 2 

ranksum WTP_AVG, by(HighSensitivity)
ranksum WTP_AVG, by(LowSensitivity)
ranksum Education, by(HighSensitivity)
ranksum Income, by(HighSensitivity)


*** Bar chart WTP (Figure 9

gen id = _n
gen wtp1 = WTP_B
gen wtp2 = WTP_C
reshape long wtp , i(id) j(pos)

gen Group = 1 if pos == 1 & treatment == "Low Impact Range"
replace Group = 2 if pos == 2 & treatment == "Low Impact Range"
replace Group = 3.5 if pos == 1 & treatment == "High Impact Range"
replace Group = 4.5 if pos == 2 & treatment == "High Impact Range"
save "Plots.dta", replace

statsby, by(Group) : ci means wtp 
gen seu = mean + se
gen sel = mean - se


twoway (bar mean Group if Group==1, bfcolor("251 200 45*0.66") blcolor("251 200 45") ysize(*1) xsize(*1) lwidth(1) barw(0.85)) ///
(bar mean Group if Group==2, bfcolor("238 121 73*0.66") blcolor("238 121 73") lwidth(1) barw(0.85) bargap(-100)) ///
(bar mean Group if Group==3.5, bfcolor("238 121 73*0.66") blcolor("238 121 73") lwidth(1) barw(0.85))          ///
(bar mean Group if Group==4.5, bfcolor("18 96 104*0.66") blcolor("18 96 104") lwidth(1) barw(0.85)), ///
legend(row(1) order(1 "Very Low Impact" "(0.05 tCO{subscript:2})" 2 "Low Impact" "(0.5 tCO{subscript:2})" 4 "High Impact" "(5 tCO{subscript:2})") size(medsmall)) ///
graphregion(color(white)) plotregion(margin(b=0)) ///
xlabel(1.5 "Low Impact Range" 4 "High Impact Range", noticks labsize(medlarge) labgap(2.5)) xtitle("") ///
yla(0(10)50, labsize(medlsmall)) ytitle(Mean WTP (€), size(medlarge) margin(medium)) yscale(range(0 50) noextend)|| ///
rcap lb ub Group, blcolor(black) lpattern(dash) note(95% confidence intervals displayed, position(6) size(medsmall) margin(medsmall))
graph export "BarChart_WTP_Impact.pdf", as(pdf) replace

